use user::dto::{UserQuery,UserDTO};
use crate::user;
use domain::{gateway::UserRepository};
use infrastructure;


pub trait UserService{
    type Repository;
    fn new(repository:Self::Repository)->Self;
    fn query(&self,query:UserQuery) -> UserDTO;
}

pub struct UserServiceImpl<T:UserRepository + Clone + 'static>{
    repository: &'static T
}
impl <T:UserRepository + Clone> UserService for UserServiceImpl<T>{
    type Repository = &'static T;
    fn new(repository: Self::Repository) -> Self {
        UserServiceImpl{
            repository
        }
    }
    fn query(&self,query: UserQuery) -> UserDTO {
        let id = query.id();
        let user = self.repository.query(id);
        UserDTO::create(&user)
    }
}